#include<vector>
#include<string>
#include<iostream>
using std::string;
using std::vector;



class Solution {
public:
    vector<string> letterCombinations(string digits) {
        if (digits.empty()) return {};
        vector<string> res = {""};
        for (auto digit: digits) {
            res = this->oneLetterCombinations(res, digit);
        }
        return res;
    }

    vector<string> oneLetterCombinations(vector<string>& combinations, char s) {
        auto charvec = this->digit2charvec(s);
        //for (auto c : charvec) std::cout << c << " ";
        vector<string> results = {};
        for (auto s: combinations) {
            for (auto c: charvec) results.push_back(s + c);
        }
        return results;
    }

    vector<char> digit2charvec(char digit) {
        switch (digit)
        {
        case '2':
            return {'a', 'b', 'c'};
            break;
        case '3':
            return {'d', 'e', 'f'};
            break;
        case '4':
            return {'g', 'h', 'i'};
            break;
        case '5':
            return {'j', 'k', 'l'};
            break;
        case '6':
            return {'m', 'n', 'o'};
            break;
        case '7':
            return {'p', 'q', 'r', 's'};
            break;
        case '8':
            return {'t', 'u', 'v'};
            break;
        case '9':
            return {'w', 'x', 'y', 'z'};
            break;
        default:
            return {};
            break;
        }
    }

};

int main() {
    string digits = "23452";
    for (auto d: digits) std::cout << d << " ";
    std::cout << "\n";
    auto res = Solution().letterCombinations(digits);
    for (auto s: res) std::cout << s << "\n";
}